﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NewFormatProject.Infrastructure.Atrributes;
using NewFormatProject.Infrastructure.Dto.Requests.Objects;
using NewFormatProject.Server.Instances.Extends.Requests;
using NewFormatProject.Server.Interfaces;

namespace NewFormatProject.Api.Admin.Controllers
{
    [Authorize]
    [CheckLogin]
    public class RightConfigController : BaseController
    {
        private readonly IRightConfigServer _rightConfigServer;
        public RightConfigController(IRightConfigServer rightConfigServer) {
           _rightConfigServer = rightConfigServer;
        }
        /// <summary>
        /// 获取权限配置详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Detail(int id)
        {
            return Ok(Json(await _rightConfigServer.Detail(id)));
        }
        /// <summary>
        /// 以分页的形式获取权限配置列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Pagination(int page,int limit,string key)
        {
            return Ok(Json(await _rightConfigServer.Pagination(page,limit,key)));
        }
        /// <summary>
        /// 添加权限配置
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionLog("添加权限配置")]
        public async Task<IActionResult> Add(RequestSysRightConfigsDto dto)
        {
            return Ok(Json(await _rightConfigServer.Add(dto)));
        }
        /// <summary>
        /// 修改权限配置
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionLog("修改权限配置")]
        public async Task<IActionResult> Update(RequestSysRightConfigsDto dto)
        {
            return Ok(Json(await _rightConfigServer.Update(dto)));
        }
        /// <summary>
        /// 删除权限配置
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionLog("删除权限配置")]
        public async Task<IActionResult> Delete(RequestSysRightConfigsDto dto)
        {
            return Ok(Json(await _rightConfigServer.Delete(dto)));
        }
    }
}
